package com.rs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rs.dao.ZhReimburseMapper;
import com.rs.model.CommonResult;
import com.rs.model.ZhReimburse;
import com.rs.service.ZhReimburseService;
import com.rs.util.DateFormatUtil;

@Service
@Transactional
public class ZhReimburseServiceImpl implements ZhReimburseService {
	
	
	@Autowired
	ZhReimburseMapper zhReimburseMapper;
	

	@Override
	public  CommonResult<Integer> insertReimburse(ZhReimburse record) {
		
		int status = zhReimburseMapper.insertReimburse(record);
		if(status ==0) {
			return new  CommonResult<Integer>(200,"添加失败");
		}
		return new  CommonResult<Integer>(200,"添加成功");
	}

	@Override
	public  CommonResult<ZhReimburse> selectReimburseId(Integer reId) {
		
		ZhReimburse status = zhReimburseMapper.selectReimburseId(reId);
		if(status ==null) {
			return new  CommonResult<ZhReimburse>(200,"查询失败",null);
		}
		return new  CommonResult<ZhReimburse>(200,"查询成功",status);
	}

	/**
	 * @version:
	 * @Description:查询报销信息
	 * @author:zjw
	 * @date:2020年8月8日
	 * @param reimburse
	 * @return
	 */
	@Override
	public PageInfo<ZhReimburse> selectZhReimburse(ZhReimburse reimburse) {
		
		PageHelper.startPage(reimburse.getPageNum(), 10);
		List<ZhReimburse> list = zhReimburseMapper.selectZhReimburse(reimburse);
		for(ZhReimburse re : list){
			if(re.getReAuTime() != null){
				re.setReAuTimes(DateFormatUtil.getDateStringw(re.getReAuTime(), "yyyy-MM-dd hh:mm:ss"));
			}
			if(re.getReTime() != null){
				re.setReTimes(DateFormatUtil.getDateStringw(re.getReTime(), "yyyy-MM-dd hh:mm:ss"));
			}
		}
		PageInfo<ZhReimburse> pageinfo = new PageInfo<>(list);
		
		return pageinfo;
	}

	/**
	 * @version:
	 * @Description:
	 * @author:zjw
	 * @date:2020年8月8日
	 * @param record
	 * @return
	 */
	@Override
	public void updateReimburseAudit(ZhReimburse record) {
		
		zhReimburseMapper.updateReimburseAudit(record);
	}

}
